home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / Builtins / Time.m < prev    next >
Text File  |  1990-08-16  |  3KB  |  98 lines

  1. % @(#)Time.m    1.2  6/29/87
  2. %
  3. export _TimeObject to "Builtins"
  4.  
  5. const _TimeObject == immutable object _TimeObject
  6.   export getSignature, create
  7.   const TimeType == immutable type TimeType
  8.     function + [o : Time] -> [r : Time]
  9.       % r <- self + o
  10.     function - [o : Time] -> [r : Time]
  11.       % r <- self - o
  12.     function * [o : Integer] -> [r : Time]
  13.       % r <- self * o
  14.     function / [o : Integer] -> [r : Time]
  15.       % r <- self / o
  16.     function > [o : Time] -> [r : Boolean]
  17.       % r <- self > o
  18.     function >= [o : Time] -> [r : Boolean]
  19.       % r <- self >= o
  20.     function < [o : Time] -> [r : Boolean]
  21.       % r <- self < o
  22.     function <= [o : Time] -> [r : Boolean]
  23.       % r <- self <= o
  24.     function = [o : Time] -> [r : Boolean]
  25.       % r <- self = o
  26.     function != [o : Time] -> [r : Boolean]
  27.       % r <- self != o
  28.     function getSeconds -> [r : Integer]
  29.     function getMicroSeconds -> [r : Integer]
  30.     function asString -> [String]
  31.     function asDate -> [String]
  32.   end TimeType
  33.   function getSignature -> [result : Signature]
  34.     result <- TimeType
  35.   end getSignature
  36.   function create [seconds : Integer, microseconds : Integer] -> [result : TimeType]
  37.     result <- immutable object aTime
  38.       export +, -, *, /, >, >=, <, <=, =, !=, getSeconds, getMicroSeconds, asString,
  39.     asDate
  40.       var secs : Integer <- seconds
  41.       var msecs: Integer <- microseconds
  42.       initially
  43.     if msecs < 0 then
  44.       secs <- secs + (msecs / 1000000) - 1
  45.       msecs <- 1000000 + (msecs # 1000000)
  46.     end if
  47.     if msecs >= 1000000 then
  48.       secs <- secs + (msecs / 1000000)
  49.       msecs <- msecs # 1000000
  50.     end if
  51.       end initially
  52.       function + [o : Time] -> [r : Time]
  53.     primitive 013 [r] <- [o]
  54.       end +
  55.       function - [o : Time] -> [r : Time]
  56.     primitive 113 [r] <- [o]
  57.       end -
  58.       function * [o : Integer] -> [r : Time]
  59.     primitive 213 [r] <- [o]
  60.       end *
  61.       function / [o : Integer] -> [r : Time]
  62.     primitive 313 [r] <- [o]
  63.       end /
  64.       function > [o : Time] -> [r : Boolean]
  65.     primitive 413 [r] <- [o]
  66.       end >
  67.       function >= [o : Time] -> [r : Boolean]
  68.     primitive 513 [r] <- [o]
  69.       end >=
  70.       function < [o : Time] -> [r : Boolean]
  71.     primitive 613 [r] <- [o]
  72.       end <
  73.       function <= [o : Time] -> [r : Boolean]
  74.     primitive 713 [r] <- [o]
  75.       end <=
  76.       function = [o : Time] -> [r : Boolean]
  77.     primitive 813 [r] <- [o]
  78.       end =
  79.       function != [o : Time] -> [r : Boolean]
  80.     primitive 913 [r] <- [o]
  81.       end !=
  82.       function getSeconds -> [r : Integer]
  83.     primitive 1013 [r] <- []
  84.       end getSeconds
  85.       function getMicroSeconds -> [r : Integer]
  86.     primitive 1113 [r] <- []
  87.       end getMicroSeconds
  88.       function asString -> [r : String]
  89.     primitive 1213 [r] <- []
  90.       end asString
  91.       function asDate -> [r : String]
  92.     primitive 1313 [r] <- []
  93.       end asDate
  94.     end aTime
  95.   end create
  96. end _TimeObject
  97.